//
//  AsPopover.swift
//  onemeetingmac
//
//  Created by 张衡 on 2020/7/2.
//  Copyright © 2020 onemeeting. All rights reserved.
//

import Foundation


class AsPopover: NSObject {
    
    static let shared = AsPopover()
    
    lazy var popover: NSPopover = {
        let popover = NSPopover.init()
        popover.appearance = NSAppearance(named: .aqua)
        popover.behavior = .transient
        popover.animates = false
    
        return popover
    }()
    
    class func create(controller:NSViewController) -> AsPopover {
        let asp = AsPopover.shared
        asp.popover.contentViewController = controller
        return asp
    }
    
    func show(_ view: NSView, preferredEdge: NSRectEdge) {
        if self.popover.isShown {
            self.popover.close()
        }
        self.popover.show(relativeTo: view.bounds, of: view, preferredEdge: preferredEdge)
        self.popover.perform_detach()
    }
    
    func perform_detach() {
        self.popover.perform_detach()
    }
}
